//
//  AccountRequestTool.m
//  Learn_ObjectiveC
//  Created by 吴可高 on 16/3/21.
//  Copyright (c) 2016年 吴可高. All rights reserved.

#import "AccountRequestTool.h"
#import "PickerSourceModel.h"
#import "MunicipalModel.h"

#import "AFHTTPSessionManager.h"
#import "AFURLSessionManager.h"

@interface AccountRequestTool()
@end

@implementation AccountRequestTool
DEF_SINGLETON(AccountRequestTool)

+ (void)downloadSessTaskPath:(NSString*)path
                    savePath:(NSString*)save
                     success:(void(^)(NSString*meg,id responseObject))success
                     failure:(void(^)(NSError*error))failure
                    progress:(void(^)(int64_t progress))progress;
{
    [[HttpRequestTool sharedInstance]downloadSesssionTaskWith:path savePath:save success:^(NSString *msg, id response) {
        success(@"success",response);
    } failure:^(NSError *error) {
        
    } uploadProgess:^(int64_t progress) {
        
    }];
}

+(void)areaCityDataRequest:(NSString*)path
                   success:(void(^)(NSString* msg,id responseObject))success
                   failure:(void(^)(NSError*error))failure
{
    [[HttpRequestTool sharedInstance]postSessionTaskWithPath:path params:nil success:^(NSString *msg, id response) {
        
        NSArray * sourceArray = [PickerSourceModel objectArrayWithKeyValuesArray:response[@"data"][@"object"]];
        [sourceArray enumerateObjectsUsingBlock:^(PickerSourceModel *  _Nonnull sourcesModel, NSUInteger idx, BOOL * _Nonnull stop) {
            if (![sourcesModel.next isKindOfClass:[NSString class]]) {
                sourcesModel.twoLevels  = [PickerSourceModel objectArrayWithKeyValuesArray:sourcesModel.next];
                
                [sourcesModel.twoLevels  enumerateObjectsUsingBlock:^(PickerSourceModel * model, NSUInteger idx, BOOL * _Nonnull stop) {
                    if (![model.next isKindOfClass:[NSString class]])
                    {
                        model.threeLevels  = [MunicipalModel objectArrayWithKeyValuesArray:model.next];
                    }
                }];
            }
        }];
        success(response[@"msg"],sourceArray);
    } failure:^(NSError *error) {
        
    }];;
}

@end
